#include "devicemodel.h"

deviceModel::deviceModel(QObject *parent)
    : QAbstractListModel(parent)
{
}

deviceModel::deviceModel(QList<checkmeDevice> deviceList, QObject *parent)
    : QAbstractListModel(parent)
{
    this->deviceList = deviceList;
}

QVariant deviceModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (role != Qt::DisplayRole)
        return QVariant();

    if (orientation == Qt::Horizontal) {
        switch (section) {
            case 0:
                return tr("DeviceList");

            default:
                return QVariant();
        }
    }
    return QVariant();
}

//QModelIndex deviceModel::index(int row, int column, const QModelIndex &parent) const
//{
//    Q_UNUSED(parent);
////    if(row < 0 && row < deviceList.size())
////        return QModelIndex();

//    //checkmeDevice *device = new checkmeDevice(deviceList.value(row));

////    if (!device)
////        return QModelIndex();

//    return createIndex(row, column, &deviceList.value(row));
//}

int deviceModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return deviceList.size();
}

QVariant deviceModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= deviceList.size())
        return QVariant();

    if (role == Qt::DisplayRole){
        return QVariant::fromValue(deviceList.at(index.row()));
        //return deviceList.at(index.row()).name;
    }else{
        return QVariant();
    }
}
